/**
 * 
 */
package implementation;

import java.awt.Color;
import java.awt.event.ComponentEvent;

import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;

/**
 * <br><b>User'</b>s end communication window , used to get user parameters and return processed output</br>
 * <b>Extends</b> JFrame
 * @author NextEpisode1
 * @version 1.6
 * @since 30/4/2011
 */
public class MainForm extends JFrameStub{
	private static final long serialVersionUID = 1L;
		/**Window width*/
	private final int WIDTH=800;
		/**Window height*/
	private final int HEIGHT=600;
		/**Hosts input boxes and control buttons*/
	private JPanel controlPan;
		/**Hosts the visual representation of the function*/
	private GraphPannel graphPan;
		/**Hosts textual output to user*/
	private JPanel outPan;
		/**Function box*/
	private JTextField funcField;
		/**Function label*/
	private JLabel funcLbl;
		/**X value*/
	private JLabel xLbl;
		/**X label*/
	private JTextField xField;
		/**Compute button*/
	private JButton compBtn;
		public JTextField getSimDerivateBox() {
			return simDerivateBox;
		}

		/**Evaluate label*/
	private JLabel functEvalLbl;
		/**Evaluate output box*/
	private JTextField evalBox;
		/**Symbolic derivative label*/
	private JLabel simDerivateLbl;
		/**Symbolic derivative box*/
	private JTextField simDerivateBox;
		/**Calculated derivative label*/
	private JLabel calcDerivativeLbl;
		public JTextField getCalcDerivativeBox() {
			return calcDerivativeBox;
		}

		/**Calculated derivative box*/
	private JTextField calcDerivativeBox;

	/**
	* Builds an fully filed and visible Window
	*/
	public MainForm() {
		super();
		setSize(WIDTH,HEIGHT);
		super.addListener();
		setLayout(null);
		initComponents();
		addComponents();
		setVisible(true);
		setDefaultCloseOperation(DISPOSE_ON_CLOSE);
		
	}

	/**Initializes the components , sizes and layouts
	 * @return void
	 * @param void
	 */
	private void initComponents(){
		
		//start of controller panel
		
		controlPan = new JPanel();
		controlPan.setBackground(Color.gray);
		controlPan.setBounds(0,0,getWidth()/3,getHeight()/2-5);
		controlPan.setLayout(null);	
		
		funcLbl = new JLabel("f(x)");
		funcLbl.setBounds(10, 30, 30, 20);
		funcField = new JTextField();
		funcField.setBounds(30, 30, controlPan.getWidth()-40, 20);
		xLbl = new JLabel("x");
		xLbl.setBounds(10, 100, 30, 20);
		xField = new JTextField();
		xField.setBounds(30, 100, controlPan.getWidth()-40, 20);
		compBtn = new JButton("Compute");
		compBtn.setSize(100, 40);
		compBtn.setLocation((controlPan.getWidth()-compBtn.getWidth())/2, 200);
		compBtn.addActionListener(new ComputeButtonActionListener(this));
		
		//end of controller panel
		//start of outP panel
		
		outPan = new JPanel();
		outPan.setBackground(Color.gray);
		outPan.setBounds(0, getHeight()/2+5, getWidth()/3, getHeight());
		outPan.setLayout(null);
		
		functEvalLbl = new JLabel("Eval f(x)");
		functEvalLbl.setBounds(10, 30, 70, 20);
		evalBox = new JTextField();
		evalBox.setBounds(70, 30, outPan.getWidth()-80, 20);
		evalBox.setEditable(false);
		simDerivateLbl = new JLabel("Sim f'(x)");
		simDerivateLbl.setBounds(10, 100, 70, 20);
		simDerivateBox = new JTextField();
		simDerivateBox.setBounds(70, 100, outPan.getWidth()-80, 20);
		simDerivateBox.setEditable(false);
		calcDerivativeLbl = new JLabel("f'(x)");
		calcDerivativeLbl.setBounds(10, 170, 70, 20);
		calcDerivativeBox = new JTextField();
		calcDerivativeBox.setBounds(70, 170, outPan.getWidth()-80, 20);
		calcDerivativeBox.setEditable(false);
		
		//end of out panel
		//start of graph panel
		
		
		graphPan = new GraphPannel(this);
		graphPan.setBackground(Color.black);
		graphPan.setBounds(getWidth()/3, 0, getWidth()-getWidth()/3, getHeight());

		
	}

	public JTextField getFuncField() {
		return funcField;
	}

	public JTextField getxField() {
		return xField;
	}

	public JTextField getEvalBox() {
		return evalBox;
	}

	/**Adds components and sets their specific components
	 * @return void
	 * @param void
	 * */
	private void addComponents(){
		controlPan.add(funcLbl);
		controlPan.add(funcField);
		controlPan.add(xLbl);
		controlPan.add(xField);
		controlPan.add(compBtn);

		
		outPan.add(evalBox);
		outPan.add(functEvalLbl);
		outPan.add(simDerivateLbl);
		outPan.add(simDerivateBox);
		outPan.add(calcDerivativeLbl);
		outPan.add(calcDerivativeBox);
		
		

		add(controlPan);
		add(outPan);
		add(graphPan);
		
		
		
	}
	
	/**
	 * <b>Resize</b>
	 * function called when resize event occurs 
	 * resizes the component panels of the frame according to frame's size
	 */
	public void componentResized(ComponentEvent arg0) {
		controlPan.setBounds(0,0,getWidth()/3,getHeight()/2-5);
		outPan.setBounds(0, getHeight()/2+5, getWidth()/3, getHeight());
		graphPan.setBounds(getWidth()/3, 0, getWidth()-getWidth()/3, getHeight());
	}
}
